const https = require('https')
const http = require('http')
const fs = require('fs');
const path = require('path')
const express=require('express')
const cors = require('cors');
const app=express()
const zhuanjiRouter=require('./router/zhuanji')
const cateRouter=require('./router/category')
const userRouter=require('./router/user')
const bodyparser=require('body-parser')
const commentRouter=require('./router/comment')
const searchRouter=require('./router/search')
const adminUserRouter=require('./admin_router/user')
const adminZhuanji=require('./admin_router/zhuanji')
const adminCategory=require('./admin_router/category')
const adminJipu=require('./admin_router/jipu')
const adminShoucang=require('./admin_router/shoucang')
app.use(bodyparser.json())
app.use(bodyparser.urlencoded({extended:false}))
app.use(cors({
    origin:'*'
}))

// 挂在静态资源
app.use(express.static('./image'))

// 挂载路由
app.use('/zhuanji',zhuanjiRouter)
app.use('/category',cateRouter)
app.use('/user',userRouter)
app.use('/comment',commentRouter)
app.use('/search',searchRouter)
app.use('/adminUser',adminUserRouter)
app.use('/adminZhuanji',adminZhuanji)
app.use('/adminCategory',adminCategory)
app.use('/adminJipu',adminJipu)
app.use('/adminShoucang',adminShoucang)
const httpOptions={
    key:fs.readFileSync(path.join(__dirname,'./czy.mathobj.xyz.key')),
    cert:fs.readFileSync(path.join(__dirname,'./czy.mathobj.xyz_bundle.pem'))
}
const httpSer = http.createServer(app).listen(9999);
const httpServer = https.createServer(httpOptions,app);

httpServer.listen(8888,()=>{
    console.log('my app is running 8888')
})